import { useTransitionFallthrough } from 'element-plus'
import { createStore } from 'vuex'
//引入封装好的仓库模块
import menu from './modules/menu'
// 引入角色管理仓库
import role from './modules/role'
// 引入管理员管理仓库
import user from './modules/user'

export default createStore({
  state: {
    userinfo:sessionStorage.getItem('userinfo')? JSON.parse(sessionStorage.getItem('userinfo')+'') :null
  },
  getters: {
    getUser(state){
      return state.userinfo
      }
  },
  mutations: {
    REQ_USERINFO(state,payload){
      if(payload){
        //登录成功，把数据存储到会话存储
        sessionStorage.setItem('userinfo',JSON.stringify(payload))
        state.userinfo = payload
      }else{
        // 退出登录
        //移除存储
        sessionStorage.removeItem('userinfo')
      }
    }
  },
  actions: {
    //封装一个行动触发mutation
    changeUserAction({commit},payload){
      commit('REQ_USERINFO',payload)
    }
  },
  modules: {
    menu,
    role,
    user
  }
})
